using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ghost : MonoBehaviour
{
    public float continueTime;
    public float alphaDelta;
    private SpriteRenderer spriteRenderer;

    private void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
    }

    public void Init(Sprite sprite)
    {
        spriteRenderer.sprite = sprite;
        Invoke("BackToPool", continueTime);
    }

    private void Update()
    {
        spriteRenderer.color = new Color(1, 1, 1, spriteRenderer.color.a * alphaDelta);
    }

    private void BackToPool()
    {
        spriteRenderer.sprite = null;
        spriteRenderer.color = new Color(1, 1, 1, 1);
        Destroy(gameObject);
    }

}
